from django.shortcuts import get_object_or_404, render_to_response
from ftbexplorer.core.models import XMLFile, Sentence
from linguistique.extracteurs import Sentence2Clause
from linguistique.tests import est_connecteur
# Create your views here.

def sentence(request, filename, nb):
    file = get_object_or_404(XMLFile, name=filename)
    sentence = get_object_or_404(Sentence, nb=nb, file=file)
    return render_to_response('sentence.html', {'sentence':sentence})


def get_fnd(request, filename, nb):
    file = get_object_or_404(XMLFile, name=filename)
    sentence = get_object_or_404(Sentence, nb=nb, file=file)
    fnd = Sentence2Clause(sentence)
    return render_to_response('fnd.html', {'fnd':fnd})
    
def get_connecteurs(request, filename, nb):
    file = get_object_or_404(XMLFile, name=filename)
    sentence = get_object_or_404(Sentence, nb=nb, file=file)
    resp = []
    for w in sentence.words():
        resp += [(w, est_connecteur(w))]
    
    return render_to_response('connecteurs.html', 
        {
            'resp':resp,
            'sentence': sentence,
        })
    